import time
from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.by import By
#
# 配置移动端设备信息
des_caps = {
    "platformName": "Android",  # 移动端系统平台
    "platformVersion": "12",  # 平台对应版本
    "deviceName": "mumu",  # 设备名称（可以随便写）
    "appPackage": "com.tpshop.malls",  # 包名
    "appActivity": ".SplashActivity"  # Activity页面名
}
# 初始化设备配置信息
option = UiAutomator2Options().load_capabilities(des_caps)
# 创建驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=option)

time.sleep(5)
#浏览翻页
for i in range(3):
    driver.swipe(1000,1250,200,1250,100)
    time.sleep(1)
time.sleep(6)
#点击我的
driver.find_element(By.ID,'com.tpshop.malls:id/mine_img').click()
#点击登录
driver.find_element(By.CLASS_NAME,'android.widget.TextView').click()
time.sleep(3)
#输入手机号和密码
driver.find_element(By.ID,'com.tpshop.malls:id/mobile_et').send_keys('13100001010')
driver.find_element(By.ID,'com.tpshop.malls:id/pwd_et').send_keys('asd123456')
time.sleep(3)
driver.find_element(By.ID,'com.tpshop.malls:id/agree_btn').click()
time.sleep(3)
driver.find_element(By.ID,'com.tpshop.malls:id/login_tv').click()
time.sleep(3)
#点击分类
# driver.find_element(By.ID,'com.tpshop.malls:id/category_ll').click()
# 点击首页
driver.find_element(By.ID,'com.tpshop.malls:id/home_ll').click()
time.sleep(3)
#点击搜素
driver.find_element(By.ID,'com.tpshop.malls:id/default_search_et').click()
time.sleep(3)
#输入搜索内容
driver.find_element(By.ID,'com.tpshop.malls:id/search_et').send_keys('华为手机')
time.sleep(3)
#点击搜索
driver.find_element(By.ID,'com.tpshop.malls:id/search_btn').click()
time.sleep(3)
#点击商品
driver.find_element(By.ID,'com.tpshop.malls:id/product_pic_img').click()
time.sleep(3)
# 点击加入购物车
driver.find_element(By.ID,'com.tpshop.malls:id/add_cart_tv').click()
time.sleep(3)
#点击确定
driver.find_element(By.ID,'com.tpshop.malls:id/confirm_tv').click()
time.sleep(3)
#点击购物车
driver.find_element(By.ID,'com.tpshop.malls:id/bottom_cart_img').click()
time.sleep(3)
#点击立即购买
driver.find_element(By.ID,'com.tpshop.malls:id/buy_tv').click()
time.sleep(3)
#提交订单
time.sleep(3)
driver.find_element(By.ID,'com.tpshop.malls:id/submit_tv').click()
#立即支付
driver.find_element(By.ID,'com.tpshop.malls:id/pay_btn').click()
time.sleep(3)
#输入·支付密码
driver.find_element(By.ID,'com.tpshop.malls:id/pwd_et').send_keys('asd123456')
time.sleep(3)
#点击支付确认
driver.find_element(By.ID,'com.tpshop.malls:id/sure_tv').click()
time.sleep(3)
#查看订单
driver.find_element(By.ID,'com.tpshop.malls:id/check_order_tv').click()



#选择手机
# driver.find_element(By.ID,'com.tpshop.malls:id/category_item_tv').click()
# #点击商品
# driver.find_element(By.ID,'com.tpshop.malls:id/product_pic_img').click()
# #点击立即购买
# driver.find_element(By.ID,'com.tpshop.malls:id/buy_now_btn').click()









